import Vue from 'vue';
import VueRouter from 'vue-router';
import Login from '../components/login.vue';
import Register from '../components/register';
import Menu from '../components/menu';
import Welcome from "../components/Welcome";
import UserList from "../components/admin/UserList";
Vue.use(VueRouter)
const routes = [
  {
    path: '/login',
    name: 'login',
    component: Login,
    meta:{
      index:0,
      name:'登录页面'
    }
  },
  {
    path: '/register',
    name: 'register_index',
    component: Register,
    meta:{
      index:0,
      name:'注册页面'
    }
  },
  {
    path: '/menu',
    name: 'menu',
    component: Menu,
    redirect:"/welcome",
    children:[
      {
        path: '/welcome',
        component: Welcome,
      },
      {
        path: '/user',
        component: UserList,
      }
    ]

  }
]

const router = new VueRouter({
  routes,
  mode:"history"
})

export default router

//挂载路由导航
// router.beforeEach((to, from,next) =>{
//   //to 将要访问
//   // from 从哪儿访问
//   //next 接着做next（url）重定向到url上 next()接续访问to路径
//   if(to.path=='../login')
//     return next();
//   //获取user
//   const userFlage=window.sessionStorage.getItem("user");
//   if(!userFlage)
//     return next('../login');
//   next();//符合要求放行
// })